﻿using System;
using MugenInjection.Infrastructure;
using MugenInjection.Interception.Interface;

// ReSharper disable CheckNamespace
namespace MugenInjection.Interception
// ReSharper restore CheckNamespace
{
    /// <summary>
    /// Adapter for convert <see cref="ISimpleInterceptorProcess"/> to <see cref="IInterceptorProcess"/>.
    /// </summary>
    public class SimpleInterceptorProcessAdapter : IInterceptorProcess
    {
        #region Fields

        private readonly ISimpleInterceptorProcess _interceptorProcess;

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="SimpleInterceptorProcessAdapter"/> class.
        /// </summary>
        public SimpleInterceptorProcessAdapter(ISimpleInterceptorProcess interceptorProcess)
        {
            Validate.ArgumentNotNull(interceptorProcess, "interceptorProcess");
            _interceptorProcess = interceptorProcess;
        }

        #endregion

        #region Implementation of ISimpleInterceptorProcess

        private void Intercept(IInterceptor methodInterceptor)
        {
            _interceptorProcess.Intercept(methodInterceptor);
        }

        #endregion

        #region Implementation of IInterceptorProcess

        /// <summary>
        /// Intercept the method using the specified <see cref="IMethodInterceptor"/>.
        /// </summary>
        /// <param name="methodInterceptor">The specified <see cref="IMethodInterceptor"/>.</param>
        public void InterceptMethod(IMethodInterceptor methodInterceptor)
        {
            Intercept(methodInterceptor);
        }

        /// <summary>
        /// Intercept the get property method using the specified <see cref="IPropertyGetInterceptor"/>.
        /// </summary>
        /// <param name="propertyGetInterceptor">The specified <see cref="IPropertyGetInterceptor"/></param>
        public void InterceptGetProperty(IPropertyGetInterceptor propertyGetInterceptor)
        {
            Intercept(propertyGetInterceptor);
        }

        /// <summary>
        /// Intercept the set property method using the specified <see cref="IPropertySetInterceptor"/>.
        /// </summary>
        /// <param name="propertySetInterceptor">The specified <see cref="IPropertySetInterceptor"/>.</param>
        public void InterceptSetProperty(IPropertySetInterceptor propertySetInterceptor)
        {
            Intercept(propertySetInterceptor);
        }

        /// <summary>
        /// Intercept the add event method using the specified <see cref="IEventAddInterceptor"/>.
        /// </summary>
        /// <param name="eventAddInterceptor">The specified <see cref="IEventAddInterceptor"/>.</param>
        public void InterceptAddEvent(IEventAddInterceptor eventAddInterceptor)
        {
            Intercept(eventAddInterceptor);
        }

        /// <summary>
        /// Intercept the remove event method using the specified <see cref="IEventRemoveInterceptor"/>.
        /// </summary>
        /// <param name="eventRemoveInterceptor">The specified <see cref="IEventRemoveInterceptor"/>.</param>
        public void InterceptRemoveEvent(IEventRemoveInterceptor eventRemoveInterceptor)
        {
            Intercept(eventRemoveInterceptor);
        }

        /// <summary>
        /// Gets the priority.
        /// </summary>
        public int Priority
        {
            get { return _interceptorProcess.Priority; }
        }

        #endregion
    }
}